<?php

namespace app\api\controller\web;


use app\admin\model\Org;
use app\admin\model\Role;
use app\admin\model\Shopcharge;
use app\admin\model\Shopchargeconfig;
use app\admin\model\Shopdevice;
use app\admin\model\Shoporder;
use app\admin\model\Shoproomset;
use app\admin\model\Shoptuan;
use app\admin\model\Shopwifi;
use app\admin\model\Tuanorder;
use app\common\controller\Api;
use OSS\OssClient;
use think\Config;

/**
 *
 */
class Staff extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];




    public function getList()
    {
        $user = $this->auth->getUser();
        $shop_id = $this->request->param('shop_id');
        $page = $this->request->param('page');
        $limit = 10;
        $offset = ($page - 1) * $limit;

        $orgModel = new Org();
        $org = $orgModel->where('mobile',$user['mobile'])->find();

        if(!$org){
            $roleModel = new Role();
            $role = $roleModel->where('mobile',$user['mobile'])->find();
            $org = $orgModel->where('id',$role['org_id'])->find();
        }

        $where = array();
        $where['Shop.org_id'] = $org['id'];

        if($shop_id != -1 && $shop_id != ""){
            $where['shop_id'] =$shop_id;
        }

        $shopStaffModel = new \app\admin\model\Shopstaff();
        $list = $shopStaffModel->with(['shop'])->limit($offset,$limit)->where($where)->select();
        $count = $shopStaffModel->with(['shop'])->where($where)->count('Shopstaff.id');

        foreach ($list as $key => $val) {

            $list[$key]['shopName']= $val['shop']['name'];
        }
        $ret = array();
        $ret['total'] =$count;
        $ret['list'] =$list;

        $this->success('请求成功', $ret);
    }



}
